﻿// This code is released under the BSD license.
namespace PugLib.Collections
{
    using System;
    using System.Collections.Generic;
    using System.Runtime.Serialization;

    [Serializable]
    public class BidirectionalDictionary<T> : Dictionary<T, T>
    {
        public BidirectionalDictionary()
        {
        }

        protected BidirectionalDictionary(SerializationInfo info, StreamingContext context)
            : base(info, context)
        {
        }

        public new void Add(T key, T value)
        {
            base[key] = value;
            base[value] = key;
        }

        public new void Remove(T key)
        {
            T value;
            if (!TryGetValue(key, out value))
            {
                return;
            }

            base.Remove(key);
            base.Remove(value);
        }
    }
}